<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>猜你喜欢的人</title>  
</head>
<body>
<div class="ui segment" id="n-page">
&nbsp;<br>
&nbsp;<br>
    <br>
<input type="hidden" name="positionid" id="positionid" value="${position.id}"/>

职位名称：
  ${position.name}
 
<br>
<h3 class="ui attached header" id="list-title">
        系统推荐候选人列表
    </h3>
    <div class="ui attached segment" id="list-items">
    <c:forEach items="${emps}" var="emp">
         <div class="ui segment listitem2 position" data-position-id="${emp.id}">
            <span class="hideName">${emp.name}</span>  &nbsp; &nbsp;&nbsp; ${emp.companyName}   &nbsp;&nbsp;&nbsp; ${emp.roleName}<br>
        </div>
    </c:forEach>    
    </div>

    <div class="ui segment" id="btn-next2">
        <div class="fluid ui button" id="more">更多候选人</div>
    </div>
   

</div>
<input type="hidden" name="lastposition" id="lastposition" value="${fn:length(emps)}"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 
<input type="hidden" name="status" id="status" value="${position.status}"/>
<div class="ui segment" >
    <!--
    <div class="fluid ui button" id="next">编辑职位</div>
    -->
    <div class="two ui buttons"> 
        <div class="ui button active dog" id="next">编辑职位</div> 
        <div class="ui button dog" id="closeit">回首页</div> 
    </div>
</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">
	wx.config({
	    debug: false, 
	    appId: "${config.appid}",  
	    timestamp: ${config.currenttimestamp},  
	    nonceStr: "${config.nonceStr}", 
	    signature: "${config.signatureStr}", 
	    jsApiList: ['checkJsApi',
	        'onMenuShareTimeline',
	        'onMenuShareAppMessage',
	        'onMenuShareQQ',
	        'onMenuShareWeibo',
	        'showOptionMenu']  
	});

    var datasource = {
        moredata: function() {
            var offset  = $('#lastposition').val();
            var hasmore = $('#hasmoredata').val();
            var positionid  = $("#positionid").val();
            var getUrl = '${ctx}/wechat/hunter/hr/moreJobRecommend.do?jobid='+positionid;
            getUrl += "&offset=" + offset;

            if(hasmore != "yes"){
                alert("已经没有更多数据了");
                return false;
            }

            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) {
            var offset = parseInt($('#lastposition').val());
            var divstring = "";
            var recommends = data.recommends;

            var count = recommends.length;
            offset += parseInt(count);
            $('#lastposition').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
                alert("已经没有更多数据了");
            }
			for (var i in recommends) {
                var emp = recommends[i];
                divstring += "<div class='ui segment listitem2 position' data-position-id='"+emp.id+"'> "
		        divstring += "   "+emp.name+"  &nbsp; &nbsp;&nbsp; "+emp.companyName+"   &nbsp;&nbsp;&nbsp; "+emp.roleName+"<br>"
		        divstring += " </div>"
            }
            var newdata = $(divstring);
            $('#list-items').append(newdata);
        }
    };

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 
            if($(this).attr('id') == 'more') {
                datasource.moredata();
            }
            if($(this).attr('id') == 'next') {
                $(this).addClass('disabled');

                var positionid  = $("#positionid").val();
                location.href = '${ctx}/wechat/hunter/hr/toEditJob.page?positionid='+positionid;
            }

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }
        } 
    };

    $(document).ready(function() { 

        	var positionid  = $("#positionid").val();
            $('.button').on('click', handler.activate);
            
            $('.position').on('click', function() {
                var empid = $(this).attr('data-position-id');
                var getUrl = '${ctx}/wechat/hunter/hr/toViewCandidate.do?empid='+empid+'&jobid='+positionid;
                location.href = getUrl;
            });
        
            //20191128 add by 李想  由原姓名展示变更为隐藏名 李尚良提出，详见20191125excel开发进度表
    		var hideSpan=document.querySelectorAll(".hideName");
    		hideSpan.forEach(function(i,j){
    			console.log(i);
    			i.innerHTML=hidden(i.innerHTML, 1, 0);
    		})
    		hideSpan.innerHTML=hidden(hideSpan.innerHTML, 1, 0);
    		
            var status  = $("#status").val();
            if(status >= 1) {
                $("#next").addClass('disabled');
            }
            wx.ready(function() {
<c:choose>
    <c:when test="${position.platformID == 2 }">
            wx.onMenuShareAppMessage({
                title: 'Headoffer--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });
    </c:when>
    <c:otherwise>
            wx.onMenuShareAppMessage({
                title: '跳哪里--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: '跳哪里--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg'
            });
    </c:otherwise>
</c:choose>
            wx.showOptionMenu();

        });

    });
    
   	function hidden(str, frontLen, endLen) {
        var len = str.length - frontLen - endLen;

        var xing = '';
        for (var i = 0; i < len; i++) {
            xing += '*';
        }
        return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
	}

</script>
</body>
</html>